﻿using System;
using System.Collections.Generic;
using System.Data.Entity.ModelConfiguration;
using System.Linq;
using WorkBasket.Data.Entities;

namespace WorkBasket.Infrastructure
{

    public class DomainUnitConfig : EntityTypeConfiguration<DomainUnit>
    {
        public DomainUnitConfig()
        {
            this.HasKey(c => c.DomainUnitID);
       

        }
    }


    public class DomainConfig : EntityTypeConfiguration<Domain>
    {
        public DomainConfig()
        {
            this.HasKey(c => c.DomainID);
 
        }
    }
    public class UnitConfig : EntityTypeConfiguration<Unit>
    {
        public UnitConfig()
        {
            this.HasKey(c => c.UnitID);
 
        }
    }

    public class GroupConfig : EntityTypeConfiguration<Group>
    {
        public GroupConfig()
        {
            this.HasKey(c => c.GroupID);
            this.HasRequired(c => c.Unit)
                .WithMany(c => c.Groups);



        }
    }


    public class WorkflowConfig : EntityTypeConfiguration<Workflow>
    {
        public WorkflowConfig()
        {
            this.HasKey(c => c.WorkflowID);
            this.HasRequired(c => c.Unit)
                .WithMany(c => c.Workflows);
           
               
 
        }
    }
    public class FieldConfig : EntityTypeConfiguration<Field>
    {
        public FieldConfig()
        {
            this.HasKey(c => c.FieldID);

            this.HasRequired(c => c.Workflow)
                .WithMany(c => c.Fields);
               
 

        }
    }
    public class VersionConfig : EntityTypeConfiguration<ProcessVersion>
    {
        public VersionConfig()
        {
            this.HasKey(c => c.ProcessVersionID);

            this.HasRequired(c => c.Workflow)
                .WithMany(c => c.ProcessVersions)
                .HasForeignKey(c => c.WorkflowID)
                .WillCascadeOnDelete(true);
                



        }
    }
    public class StepConfig : EntityTypeConfiguration<Step>
    {
        public StepConfig()
        {
            this.HasKey(c => c.StepID);

            this.HasRequired(c => c.ProcessVersion)
                .WithMany(c => c.Steps)
                .HasForeignKey(f => f.ProcessVersionID);


            this.HasOptional(c => c.ParentStep)
                .WithMany(e => e.ChildSteps);



        }
    }
    public class FormConfig : EntityTypeConfiguration<Form>
    {
        public FormConfig()
        {
            this.HasKey(c => c.FormID);

            this.HasRequired(c => c.Workflow)
                .WithMany(c => c.Forms)
                .HasForeignKey(f => f.WorkflowID);

        }
    }
   public class ControlConfig : EntityTypeConfiguration<FormControl>
   {

       public ControlConfig()
       {
           this.HasKey(c => c.FormControlID);

           this.HasRequired(c => c.Form)
               .WithMany(c => c.FormControls)
               .HasForeignKey(c => c.FormID);


           this.HasOptional(c => c.ParentControl)
               .WithMany(e => e.ChildControls);

       }
   }
    public class InstanceConfig:EntityTypeConfiguration<Instance>
    {
        public InstanceConfig()
        {
            this.HasKey(c => c.InstanceID);


        }

    }
    public class InstanceHistoryConfig:EntityTypeConfiguration<InstanceHistory>
    {

        public InstanceHistoryConfig ()
	    {
            this.HasKey(c => c.InstanceHistoryID);
	    }
      

    }
}
